package designpattern

import (
	"sync"
	"time"
)

type Singleton struct {
	CurrTime time.Time
}

var once sync.Once
var onceInstance *Singleton

func OnceFunc() *Singleton {
	once.Do(func() {
		onceInstance = &Singleton{CurrTime: time.Now()}
	})
	return onceInstance
}

var lazyInstance *Singleton
var lock sync.Mutex

func LazyFunc() *Singleton {
	if lazyInstance == nil {
		lock.Lock()
		if lazyInstance == nil {
			lazyInstance = &Singleton{CurrTime: time.Now()}
		}
		lock.Unlock()
	}

	return lazyInstance
}

var hungryInstance = &Singleton{CurrTime: time.Now()}

func HungryFunc() *Singleton {
	return hungryInstance
}
